<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闭包陷阱</title>
</head>
<body>
    <button id="btn">add</button>
    <button id="btn1">add1</button>
</body>
<script>
    // document.getElementById('btn1') 本身就代表一次引用，内存泄漏还存在
    function foo() {
        var el = document.getElementById('btn');

        el.onclick = function () {
            console.log(el.id);
        }

    }
    foo();

    // document.getElementById('btn1') 引用被释放
    function foo1() {
        var el = document.getElementById('btn1');

        el.onclick = function () {
            console.log(el.id);
        }

        el = null;
    }
    foo1();
</script>
</html>